<?php
error_reporting(0);
$s = new \SDK();
$token = $s->getToken();
var_dump($token);
$data = array('abb'=>1,'bbb'=>2);
$s->pushShop($data, $token);

class SDK {

    const TOKEN_URL = 'http://www.novice.com/association/service/getToken';
    const REUQEST_URL = 'http://www.novice.com/association/service/pushShop';

    public function getToken() {
        return trim($this->m_post(self::TOKEN_URL));
    }
    
    public function pushShop($data,$token){
        $sign = $this->createSian($data,$token);
        $re = $this->m_post(self::REUQEST_URL.'?sign='.$sign,$data);
        var_dump($re);
    }
    
    public function createSian($data,$token){
        ksort($data);
        $str = '';
        foreach($data as $k=>$v){
            $str .= $k.'='.$v.'&';
        }
        var_dump($token.substr($str,0,-1));
        return md5($token.substr($str,0,-1));
    }

    private function m_post($url, $data, $timeout = 30) {
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1);
        curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
        curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($curl, CURLOPT_AUTOREFERER, 1);
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
        curl_setopt($curl, CURLOPT_TIMEOUT, $timeout);
        curl_setopt($curl, CURLOPT_HEADER, false);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $tmpInfo = curl_exec($curl);
        if (curl_errno($curl)) {
            echo 'Errno' . curl_error($curl);
        }
        curl_close($curl);
        return $tmpInfo;
    }

}
